import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';

export default async function a002(fd: IFeidaoAiBrowserComponent, e: Event) {// 排序
	// todo
	console.log('zj-000003:a002------start');

	const n = e.target as HTMLDivElement;
	const v = n.getAttribute('data-id');

	const flag = n.getAttribute('data-flag');
	const ns = fd.data.node.querySelectorAll('[data-asc="desc"]');/*querySelectorAll找到所有的 ，querySelector 找到符合条件的第一个*/
	Array.from(ns).forEach((value: HTMLDivElement) => {
		value.setAttribute('class', 'iconfont corsor-p icon-shangxia color-3 font14 pos-a');
	});

	const asc: string[] = [];
	const desc: string[] = [];

	if (flag === '1') {
		/*升序*/
		n.setAttribute('data-flag', '0');
		n.setAttribute('class', 'iconfont corsor-p icon-shang color-3 font14 pos-a');
		asc.push(v);
	} else {
		/*降序 */
		n.setAttribute('data-flag', '1');
		n.setAttribute('class', 'iconfont corsor-p icon-xia color-3 font14 pos-a');
		desc.push(v);
	}

	// 获取隐患源特性名称
	const hn = fd.data.node.querySelector<HTMLInputElement>('[data-id="hidden_name"]');// 获取输入查询的内容
	const hnv = hn.value;
	console.log(hnv);
	// 搜索
	const res = await nodejs<{ res: Array<{}>; c: number }>('wyf-hManager/zj-000003/s001', {
		filter: {
			hidden_name: hnv,
			pn: 1,
			asc,
			desc
		}
	});
	console.log(res);
	render(fd, res, p001, 'p001', 'inner');

	console.log('zj-000003:a002------end');
}
